const { v4: uuidv4 } = require('uuid');

/**
 * 创建常用字典数据
 */
module.exports = {
  up: async (queryInterface) => {
    const now = new Date();

    // 字典类型数据
    const dictionaryTypes = [
      {
        id: uuidv4(),
        code: 'user_status',
        name: '用户状态',
        english: 'User Status',
        description: '用户账号状态',
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        code: 'user_type',
        name: '用户类型',
        english: 'User Type',
        description: '用户账号类型',
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        code: 'gender',
        name: '性别',
        english: 'Gender',
        description: '用户性别',
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        code: 'common_status',
        name: '通用状态',
        english: 'Common Status',
        description: '通用启用/禁用状态',
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        code: 'tenant_status',
        name: '租户状态',
        english: 'Tenant Status',
        description: '租户账号状态',
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        code: 'menu_type',
        name: '菜单类型',
        english: 'Menu Type',
        description: '菜单项类型',
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        code: 'yes_no',
        name: '是否',
        english: 'Yes/No',
        description: '通用是否选项',
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        code: 'billing_cycle',
        name: '计费周期',
        english: 'Billing Cycle',
        description: '套餐计费周期',
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        code: 'support_level',
        name: '支持级别',
        english: 'Support Level',
        description: '客户支持服务级别',
        status: true,
        created_at: now,
        updated_at: now,
      },
    ];

    await queryInterface.bulkInsert('dictionary_types', dictionaryTypes);

    // 字典项数据
    const dictionaryItems = [];

    // 用户状态
    const userStatusType = dictionaryTypes.find((t) => t.code === 'user_status');
    dictionaryItems.push(
      {
        id: uuidv4(),
        type_id: userStatusType.id,
        label: '正常',
        english: 'Active',
        value: 'active',
        order_num: 1,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: userStatusType.id,
        label: '禁用',
        english: 'Inactive',
        value: 'inactive',
        order_num: 2,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: userStatusType.id,
        label: '锁定',
        english: 'Locked',
        value: 'locked',
        order_num: 3,
        status: true,
        created_at: now,
        updated_at: now,
      },
    );

    // 用户类型
    const userTypeType = dictionaryTypes.find((t) => t.code === 'user_type');
    dictionaryItems.push(
      {
        id: uuidv4(),
        type_id: userTypeType.id,
        label: '超级管理员',
        english: 'Super Admin',
        value: 'super_admin',
        order_num: 1,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: userTypeType.id,
        label: '租户管理员',
        english: 'Tenant Admin',
        value: 'tenant_admin',
        order_num: 2,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: userTypeType.id,
        label: '普通用户',
        english: 'Normal User',
        value: 'normal',
        order_num: 3,
        status: true,
        created_at: now,
        updated_at: now,
      },
    );

    // 性别
    const genderType = dictionaryTypes.find((t) => t.code === 'gender');
    dictionaryItems.push(
      {
        id: uuidv4(),
        type_id: genderType.id,
        label: '男',
        english: 'Male',
        value: 'male',
        order_num: 1,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: genderType.id,
        label: '女',
        english: 'Female',
        value: 'female',
        order_num: 2,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: genderType.id,
        label: '未知',
        english: 'Unknown',
        value: 'unknown',
        order_num: 3,
        status: true,
        created_at: now,
        updated_at: now,
      },
    );

    // 通用状态
    const commonStatusType = dictionaryTypes.find((t) => t.code === 'common_status');
    dictionaryItems.push(
      {
        id: uuidv4(),
        type_id: commonStatusType.id,
        label: '启用',
        english: 'Enabled',
        value: 'enabled',
        order_num: 1,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: commonStatusType.id,
        label: '禁用',
        english: 'Disabled',
        value: 'disabled',
        order_num: 2,
        status: true,
        created_at: now,
        updated_at: now,
      },
    );

    // 租户状态
    const tenantStatusType = dictionaryTypes.find((t) => t.code === 'tenant_status');
    dictionaryItems.push(
      {
        id: uuidv4(),
        type_id: tenantStatusType.id,
        label: '正常',
        english: 'Active',
        value: 'active',
        order_num: 1,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: tenantStatusType.id,
        label: '试用中',
        english: 'Trial',
        value: 'trial',
        order_num: 2,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: tenantStatusType.id,
        label: '未激活',
        english: 'Inactive',
        value: 'inactive',
        order_num: 3,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: tenantStatusType.id,
        label: '已暂停',
        english: 'Suspended',
        value: 'suspended',
        order_num: 4,
        status: true,
        created_at: now,
        updated_at: now,
      },
    );

    // 菜单类型
    const menuTypeType = dictionaryTypes.find((t) => t.code === 'menu_type');
    dictionaryItems.push(
      {
        id: uuidv4(),
        type_id: menuTypeType.id,
        label: '目录',
        english: 'Directory',
        value: 'directory',
        order_num: 1,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: menuTypeType.id,
        label: '菜单',
        english: 'Menu',
        value: 'menu',
        order_num: 2,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: menuTypeType.id,
        label: '按钮',
        english: 'Button',
        value: 'button',
        order_num: 3,
        status: true,
        created_at: now,
        updated_at: now,
      },
    );

    // 是否
    const yesNoType = dictionaryTypes.find((t) => t.code === 'yes_no');
    dictionaryItems.push(
      {
        id: uuidv4(),
        type_id: yesNoType.id,
        label: '是',
        english: 'Yes',
        value: 'yes',
        order_num: 1,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: yesNoType.id,
        label: '否',
        english: 'No',
        value: 'no',
        order_num: 2,
        status: true,
        created_at: now,
        updated_at: now,
      },
    );

    // 计费周期
    const billingCycleType = dictionaryTypes.find((t) => t.code === 'billing_cycle');
    dictionaryItems.push(
      {
        id: uuidv4(),
        type_id: billingCycleType.id,
        label: '月付',
        english: 'Monthly',
        value: 'monthly',
        order_num: 1,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: billingCycleType.id,
        label: '年付',
        english: 'Yearly',
        value: 'yearly',
        order_num: 2,
        status: true,
        created_at: now,
        updated_at: now,
      },
    );

    // 支持级别
    const supportLevelType = dictionaryTypes.find((t) => t.code === 'support_level');
    dictionaryItems.push(
      {
        id: uuidv4(),
        type_id: supportLevelType.id,
        label: '基础支持',
        english: 'Basic Support',
        value: 'basic',
        order_num: 1,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: supportLevelType.id,
        label: '优先支持',
        english: 'Priority Support',
        value: 'priority',
        order_num: 2,
        status: true,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        type_id: supportLevelType.id,
        label: '专属支持',
        english: 'Dedicated Support',
        value: 'dedicated',
        order_num: 3,
        status: true,
        created_at: now,
        updated_at: now,
      },
    );

    await queryInterface.bulkInsert('dictionary_items', dictionaryItems);
  },

  down: async (queryInterface) => {
    await queryInterface.bulkDelete('dictionary_items', null, {});
    await queryInterface.bulkDelete('dictionary_types', null, {});
  },
};


